import re

from plugins import CheckPlugin
from config import logger
from helper import CallProcess, raw2lines

cmd = '/bin/df -t nonfs,nullfs,devfs'
logger.debug('check cmd: %s' % cmd)

class CheckDisk(CheckPlugin):

    topic = 'harddisk'
    # results = []

    def check(self):
        pat = re.compile(r'(%)')
        proc = CallProcess(cmd)
        proc(check_call=True)

        lines = raw2lines(proc.stdout, 1)
        for line in lines:
            values = [l.strip() for l in line.split()]
            self.results.append({'filesystem': values[0],
                                 'size': int(values[1]),
                                 'used': int(values[2]),
                                 'avail': int(values[3]),
                                 'capacity': int(pat.sub('', values[4])),
                                 'mounted_on': values[5]
                                 })

